package graph;

import java.util.ArrayList;
import java.util.List;

public class Graph<T,V> {
	private ArrayList<Node<T>> nodes;
	private ArrayList<Edge<T,V>> edges;
	public Graph(ArrayList<Node<T>> n, ArrayList<Edge<T,V>> e) {
		nodes = n;
		edges = e;
	}
	public ArrayList<Node<T>> getNodes() {
		return nodes;
	}
	public ArrayList<Edge<T,V>> getEdges() {
		return edges;
	}
	@Override
	public String toString() {
		return "Graph [nodes=" + nodes + "\nedges=" + edges + "]";
	}
	public List<Node<?>> getNeighbours(Node<?> node) {
		ArrayList<Node<?>> result = new ArrayList<Node<?>>();
		for (Edge<?, ?> edge : edges) {
			if (edge.a == node) {
				result.add(edge.b);
			} else if (edge.b == node) {
				result.add(edge.a);
			}
		}
		return result;
	}
}
